//  UIBarButtonItem+Extension.swift
//  微博
//
//  Created by 仲启明 on 2017/1/4.
//  Copyright © 2017年 swift. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

   convenience init(title:String, imageName:String, target:Any?, action:Selector?) {
        
    let btn = UIButton()
    
    btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
    btn.setImage(UIImage(named:imageName), for: .normal)
    btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
    btn.setTitle(title, for: .normal)
    btn.setTitleColor(UIColor.darkGray, for: .normal)
    btn.setTitleColor(UIColor.orange, for: .highlighted)
    
    if let ac = action {
        
        btn.addTarget(target, action: ac, for: .touchUpInside)
    }
    
    btn.sizeToFit()
    
    self.init()
    
    self.customView = btn
    
    }
}
